function make_option(ob, i, v, t, blnSelected) {
	ob.options[i] = new Option(t, v);
	if (blnSelected) ob.options[i].selected = true;
}
function copy_option(des, src, tmp, val, sel_value,default_text){
	var len = src.options.length;
	var j=1;
	des.options.length = 0;
	des.selectedIndex = -1;
    if(default_text!=''){
        make_option(des, 0, 0, default_text, false);
    }else{
    	make_option(des, 0, 0, "--- None ---", false);
    }
	for(var i=0; i<len; i++){
		if(tmp.options[i].text==val){
			if (src.options[i].value == sel_value) {
				make_option(des, j, src[i].value, src.options[i].text, true);
			} else {
				make_option(des, j, src[i].value, src.options[i].text, false);
			}	
			j++;
		}
	}
}
function sel_active(sel_name,val){
	var f=eval("document.adminForm."+sel_name);
	for(var i=0;i<f.length;i++){
		if(f.options[i].value==val){
			f.selectedIndex=i;
			break;
		}
	}
}
function doCheckOne(frm,chk_name){
    //var f = eval("document.forms."+fname);
    if(frm){
        var len=frm.elements.length;
        var haveChecked=false;
        for(i=0 ; i<len ; i++) {
    		if ((frm.elements[i].name==chk_name) && (frm.elements[i].checked)) {
    			haveChecked = true;
              break;
    		}
    	}
    	if (haveChecked==false) {
    		//alert('Please select at least one record!');
    		return false;
    	}
      return true;
    }else{
        return;
    }
}
function doCheckNumber(frm,chk_name,number){
    //var f = eval("document.forms."+fname);	
    if(frm){
        var len=frm.elements.length;
        var haveChecked=false;
        var num = 0;
        for(i=0 ; i<len ; i++) {
    		if ((frm.elements[i].name==chk_name) && (frm.elements[i].checked)) {
    			num++;    			              
    		}
    	}
        if(num > 0 && num <= number){
        	haveChecked = true;
        }        
    	if (haveChecked==false && num > 0) {
    		//alert('Only selected '+number+' record maximum!');
    		return false;
    	}else{
    		if(num == 0){
    			//alert('Please select at least one record!');
    			return false;
    		}
    		return true;
    	}
      return true;
    }else{
        return;
    }
}
function checkAll(frm,chk_name,value){
    //var frm = eval("document.forms."+form);
    var len=frm.elements.length;
    var haveChecked=false;
    for(i=0 ; i<len ; i++) {
    	if (frm.elements[i].name==chk_name && frm.elements[i].value == value){
			frm.elements[i].checked=true;
			return true;
		}
	}
    return false;
}
function unCheckAll(frm,chk_name){
	var len=frm.elements.length;
    for(i=0 ; i<len ; i++) {
    	if (frm.elements[i].name==chk_name){
			frm.elements[i].checked=false;			
		}
	}
    return true;
}
function checkAllObj(the_form, the_box, check)
{	
	for(i=0;i<the_form.elements.length;i++)
	{
		
		if(the_form.elements[i].name==the_box)
		{			
			the_form.elements[i].checked= check;		
		}
	}
}
function checkAllObj1(num , the_box, check)
{	
	for(i=0;i<num;i++){
		document.getElementById(i+'_'+the_box).checked = check;		
	}
}
function formSubmit(frm,chk_name,task){
    //var f = eval("document.forms."+fname);
    if(!doCheckOne(frm,chk_name)){
        return;
    }
    else{
         frm.task.value=task;
         if(task=="delete"){
             if(window.confirm("Do you want to delete these selected entry ?")){
                 frm.submit();
             }
         }else{
             frm.submit();
         }
    }
}
function saveOrder(frm,chk_name){
    checkAll(frm,chk_name,true);
    frm.task.value='saveorder';
    frm.submit();
}

function image_preview(filename,objId){
	obj=document.getElementById(objId);		
	if(filename){
		var img=new Image();
		img.src=filename;
		var w=img.width;
		var h=img.height;
		obj.innerHTML='<img src="'+filename+'" width="300" border="0">';
		
	}else obj.innerHTML='Select an image';
}
function image_preview_ver2(filename){
	obj=document.getElementById("image_preview");		
	if(filename){
		var img=new Image();
		img.src=filename;
		var w=img.width;
		var h=img.height;
		obj.innerHTML='<img src="'+filename+'" width="300" border="0">';
		
	}else obj.innerHTML='Select an image';
}
function photo_preview(filename,objId,row,id,id1){
	obj=document.getElementById(objId);
	for(i=0;i<row;i++){		
		o=document.getElementById("pid"+id+'_'+i);
		if(o.checked == true){
			o.checked = false;
		}
	}
	document.getElementById(id1).checked=true;
	if(filename){
		var img=new Image();
		img.src=filename;
		var w=img.width;
		var h=img.height;
		obj.innerHTML='<img src="'+filename+'" width="320" border="0">';
		
	}else obj.innerHTML='Select an image';
}
function photo_paging(page,total,objId){
	page = page-1;
	for(i=0;i<=total-1;i++){
		obj = document.getElementById(objId+'_'+i);
		if(obj.style.display=='block'){
			obj.style.display="none";
			ob=document.getElementById(objId+'_'+page);
			ob.style.display="block";
			return true;
		}
	}
	return false;
}
function rating(value,objId){
	obj = document.getElementById(objId);
	for(i=1;i<=5;i++){
		ob = document.getElementById(i);
		if(i<=value){
			ob.src = "/images/icon_bigstar_rate.gif";
		}else{
			ob.src = "/images/icon_bigstar_norate.gif";
		}
	}
	obj.value = value;
}
function view(row,id1,id2,objid){
			obj=document.getElementById(objid);
			for(i=0;i<row;i++){
				o=document.getElementById("p"+id1+id2+i);
				ob=o.value;
				image_preview="image_preview"+ob+"p"+i;
				if(o.checked==true && document.getElementById(image_preview).style.display=="block"){
					document.getElementById(image_preview).style.display="none";
					o.checked=false;
				}
			}
			if(obj.style.display=="block")
					obj.style.display="none";
				else
					obj.style.display="block";				
			
			
}


function listItemTask(id,task ) {
    var f = document.adminForm;
    cb = eval( 'f.' + id );
    if (cb) {
        for (i = 0; true; i++) {
            cbx = eval('f.cb'+i);
            if (!cbx) break;
            cbx.checked = false;
        } // for
        cb.checked = true;
        f.task.value=task;
        f.submit();
    }
    return false;
}
function changeDynaList(select, listname, source,v1,v2,v3, key, orig_key, orig_val ) {
	var list = eval( 'document.adminForm.' + listname );
	
	// empty the list	
	for (i in list.options) {
		list.options[i] = null;		
	}	
	i = 0;
	var s = source.split("+");	
	var arr = new Array();
		
	opt = new Option();
	opt.value = 0;
	opt.text = select;
	list.options[i++] = opt;
	for (x=0;x<s.length;x++){		
		if(s[x]!=''){
			var tt = s[x].split("-");
			if((tt[1] == v1) && (tt[2]==key)){
				var t=tt;				
			}
			if(t){
				var n = s[x].split("-");			
				if((n[0] == t[0]) && (n[1] == v2)){
					opt = new Option();
					opt.value = n[2];
				}
				if((n[0] == t[0]) && (n[1] == v3)){
					opt.text = n[2];
					if ((orig_key == key && orig_val == opt.value) || i == 0) {
						opt.selected = true;
					}
					list.options[i++] = opt;
				}
			}	
		}
	}	
	list.length = i;
}
